From ba479e777ddab433630d2c12afc35a4bfe44a255 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 23 Dec 2009 16:42:34 +0000 Subject: [PATCH] Add write support to bushnell_trl. --- bushnell_trl.c | 51 +++++++++++++++++++++++++++++---- xmldoc/formats/bushnell_trl.xml | 10 +++++-- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/bushnell_trl.c b/bushnell_trl.c index 7b6dd852a..e7d85a720 100644 --- a/bushnell_trl.c +++ b/bushnell_trl.c @@ -24,6 +24,8 @@ #define MYNAME "Bushnell Trail" static gbfile *file_in; +static gbfile *file_out; +static int trkpt_count; static route_head* trk_head; static @@ -45,7 +47,30 @@ rd_init(const char *fname) { static void rd_deinit(void) { - gbfclose(file_in); + gbfclose(file_out); +} + +static void +wr_init(const char *fname) { + file_out = gbfopen_le(fname, "w", MYNAME); + trkpt_count = 0; + static char obuf[20] = {"TL003"}; + gbfwrite(&obuf, 1, 20, file_out); +} + +static void +wr_deinit(void) { + int i = trkpt_count; + while (i < 4502) { + gbfputint32(0, file_out); + gbfputint32(0, file_out); + i++; + } + gbfputint32(0, file_out); + gbfputint16(trkpt_count, file_out); + gbfputc(1, file_out); + + gbfclose(file_out); } /* @@ -72,16 +97,32 @@ bushnell_read(void) { } } +static void +bushnell_write_one(const waypoint *wpt) { + trkpt_count++; + if (trkpt_count > 4502) + fatal(MYNAME " too many trackpoints. Max is 4502."); + + gbint32 lat = wpt->latitude * 10000000.0; + gbint32 lon = wpt->longitude * 10000000.0; + gbfputint32(lat, file_out); + gbfputint32(lon, file_out); +} + +static void +bushnell_write(void) { + track_disp_all(NULL, NULL, bushnell_write_one); +} ff_vecs_t bushnell_trl_vecs = { ff_type_file, - { ff_cap_none, ff_cap_read, ff_cap_none }, + { ff_cap_none, ff_cap_read | ff_cap_write, ff_cap_none }, rd_init, - NULL, + wr_init, rd_deinit, - NULL, + wr_deinit, bushnell_read, - NULL, + bushnell_write, NULL, bushnell_args, CET_CHARSET_MS_ANSI, 0 /* Not really sure... */ diff --git a/xmldoc/formats/bushnell_trl.xml b/xmldoc/formats/bushnell_trl.xml index 34059bed5..0a17cac7e 100644 --- a/xmldoc/formats/bushnell_trl.xml +++ b/xmldoc/formats/bushnell_trl.xml @@ -1,11 +1,15 @@ -This format supports reading tracks from +This format supports tracks from Bushnell GPS receivers, notably the Onix 400. This format reads individual .trl files as written by the GPS. As this is a reverse-engineered format, it's not understood how long tracks, in -particular, spam multiple files so initially this format is most effective -on tracks under a few thousand points. +particular, span multiple files so initially this format is most effective +on tracks under a few thousand points. + + + When writing tracks, a maximum of 4502 points is supported as this is the + most we believe these units can represent in a track. -- 2.30.2